<?php

namespace App\Console\Commands;

use App\Constant\Enum;
use App\Models\Admodel;
use App\Models\Adtype;
use App\Models\Setting;
use App\Models\User;
use App\Services\User\RegisterUserService;
use App\Services\User\UserNumberService;
use App\Services\User\UserUuidService;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Cache;

class FinderCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'finder';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Test toolbox';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        // $this->makeUser();
    }

    private function makeUser()
    {
        $attribute1 = [
            'username' => 'UserA',
            'password' => '',
            'nickname' => 'UserA',
            'avatar' => url('images/avatar1.png'),
            'openid' => 'F9ZD2NTM1LTM3',
            'registered_at' => Carbon::now(),
            'last_login_at' => Carbon::now(),
            'last_login_ip' => '127.0.0.1',
        ];
        $has = User::query()->where(['openid' => $attribute1['openid']])->exists();
        if (!$has) {
            $user1 = (new RegisterUserService())->register($attribute1);
            dump($user1->toArray());
            $attribute2 = [
                'username' => 'UserB',
                'password' => '',
                'nickname' => 'UserB',
                'avatar' => url('images/avatar2.png'),
                'openid' => 'DAZLSKTP1MTZ4',
                'registered_at' => Carbon::now(),
                'last_login_at' => Carbon::now(),
                'last_login_ip' => '127.0.0.1',
            ];
            $user2 = (new RegisterUserService())->register($attribute2);
            $user2->update(['parent_id' => $user1->id]);
            dump($user2->toArray());
        }
    }
}
